package com.airspyar;

public class Timer {

	private long lastTime=0;
	private final int interval;
	private final Object lastTimeMutex=new Object();
	
	public Timer(int interval){
		this.interval=interval;
	}
	
	public void reset(){
		synchronized(lastTimeMutex){
			lastTime=0;
		}
	}
	
	public boolean intervalElapsed(){
			long currentTime=System.currentTimeMillis();
			synchronized(lastTimeMutex){
				long elapsed=currentTime-lastTime;
				if(elapsed>interval){
						lastTime=currentTime;
					return true;
				}
			}
		
		return false;
	}
}
